<!--
 * @Author: 码上talk|RC
 * @Date: 2020-11-17 15:56:43
 * @LastEditTime: 2020-12-16 16:31:17
 * @LastEditors: 码上talk|RC
 * @Description: 
 * @FilePath: /tacomall-merchant/src/components/form-box/index.vue
 * @微信:  13680065830
 * @邮箱:  3189482282@qq.com
 * @oops: Just do what I think it is right
-->
<template>
    <div class="form-box">
        <slot></slot>
    </div>
</template>

<script>
import { formToolkit } from '@/utils/form-toolkit'
export default {
    data() {
        return {
            success: true
        }
    },
    props: ['form'],
    methods: {
        validate(rule) {
            return new Promise((resolve, reject) => {
                for (let i in this.$children) {
                    if (this.$children[i].validateFiled && this.$children[i].filed && this.$children[i].filed.isRequire) {
                        if (rule && !rule.map(i => i['key']).includes(this.$children[i].filed['key'])) {
                            continue
                        }
                        this.success = this.$children[i].validateFiled()
                        if (!this.success) {
                            break
                        }
                    }
                }
                if (this.success) {
                    resolve({ success: this.success, form: formToolkit.gen(this.form) })
                } else {
                    reject()
                }
            })
        }
    }
}
</script>